<?php

declare (strict_types=1);

namespace app\store\controller\agent;


use app\store\controller\Controller;
use think\App;
use think\response\Json;
use app\store\service\agent\Withdrawal as WithdrawalService;

/**
 * 绑定操作
 * Class Setting
 * @package app\store\controller
 */
class Withdrawal extends Controller
{
    private $withdrawalService;
    public function __construct(App $app,WithdrawalService $withdrawalService)
    {
        parent::__construct($app);
        $this->withdrawalService = $withdrawalService;
    }

    /**
     * 提现记录
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function record():Json
    {
        $params = $this->request->get();
        $this->validate(
            $params,
            [
                'between_time|时间区间' => 'array',
                'promoter_user_id|推广员用户ID' => 'integer',
                'status|提现状态' => 'integer',
                'type|类型' => 'require', //all 全部  agent表示推广员
               // 'search|关键词' => ''   //会员ID 、昵称 、手机号
            ]
        );
        $list = $this->withdrawalService->getRecords($params);
        return $this->renderSuccess(compact('list'));
    }

    /**审核
     * @return Json
     */
    public function check():Json
    {
        $params = $this->request->post();
        $this->validate(
            $params,
            [
                'type' => 'require',  //1 审核通过 -1拒绝
                'id' => 'require',  //记录ID
                //'remark' => ''   //备注  拒绝必填
            ]
        );
        $res = $this->withdrawalService->check($params);
        if(!$res){
            return $this->renderError('审核异常');
        }
        return $this->renderSuccess([],'审核成功');
    }

    /**AI审核设置
     * @return Json
     */
    public function aiSet(): Json
    {
        $params = $this->request->post();
        $this->validate(
            $params,
            [
                'status|状态' => 'require'  // 1开启 -1关闭
            ]
        );
        $res = $this->withdrawalService->getAiSet($params);
        if(!$res){
            return $this->renderError('开启失败');
        }
        return $this->renderSuccess([],'操作成功');
    }


    /**AI审核设置
     * @return Json
     */
    public function aiStatus(): Json
    {
        $res = $this->withdrawalService->getAiStatus();
        return $this->renderSuccess($res);
    }




}
